// shebeixinxiLocal.js 设备信息本地存储操作工具，包含设备信息的增删查改等方法
const STORAGE_KEY = 'shebeixinxi';

export function getShebeiList() {
  return JSON.parse(localStorage.getItem(STORAGE_KEY) || '[]');
}

export function saveShebeiList(list) {
  localStorage.setItem(STORAGE_KEY, JSON.stringify(list));
}

export function addShebei(item) {
  const list = getShebeiList();
  item.id = Date.now();
  if (!item.zhuangtai) item.zhuangtai = '离线';
  list.push(item);
  saveShebeiList(list);
}

export function updateShebei(item) {
  const list = getShebeiList();
  const idx = list.findIndex(i => i.id === item.id);
  if (idx !== -1) {
    list[idx] = item;
    saveShebeiList(list);
  }
}

export function deleteShebei(ids) {
  let list = getShebeiList();
  list = list.filter(i => !ids.includes(i.id));
  saveShebeiList(list);
}

export function getShebeiById(id) {
  return getShebeiList().find(i => i.id === id);
} 